﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DESKeyMaker
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void button_generate_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            if (radioButtonX8.Checked)
            {
                string random = Guid.NewGuid().ToString().Replace("-", "").ToUpper();
                for (int i = 0; i < 8; i++)
                {
                    textBox1.Text += "0x" + random.Substring(2 * i, 2);
                   if (i != 7)
                        textBox1.Text += ", ";
                }
            }
            else if (radioButtonX16.Checked)
            {
                string random = Guid.NewGuid().ToString().Replace("-", "").ToUpper();
                for (int i = 0; i < 16; i++)
                {
                    textBox1.Text += "0x" + random.Substring(2 * i, 2);
                    if (i != 15)
                        textBox1.Text += ", ";
                }
            }
            else if (radioButtonX32.Checked)
            {
                string random = Guid.NewGuid().ToString().Replace("-", "").ToUpper();
                random += Guid.NewGuid().ToString().Replace("-", "").ToUpper();
                for (int i = 0; i < 32; i++)
                {
                    textBox1.Text += "0x" + random.Substring(2 * i, 2);
                    if (i != 31)
                        textBox1.Text += ", ";
                }
            }

            btn_Copy.Enabled = true;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            button_generate_Click(sender, e);
        }

        private void btn_Copy_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(textBox1.SelectedText))
            {
                Clipboard.SetDataObject(textBox1.SelectedText);
                MessageBox.Show("Already copy to clipboard!");
            }
        }

        private void radioButtonX16_CheckedChanged(object sender, EventArgs e)
        {
            button_generate_Click(sender, e);
        }

        private void radioButtonX8_CheckedChanged(object sender, EventArgs e)
        {
            button_generate_Click(sender, e);
        }

        private void radioButtonX32_CheckedChanged(object sender, EventArgs e)
        {
            button_generate_Click(sender, e);
        }
    }
}
